{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 1: Splice It\n",
    "\n",
    "If `thing` is a list and `low` and `high` are both non-negative integers:\n",
    "\n",
    "1. What does `thing[low:high]` do?\n",
    "2. What does `thing[low:]` (without a value after the colon) do?\n",
    "3. What does `thing[:high]` (without a value before the colon) do?\n",
    "4. What does `thing[:]` (just a colon) do?\n",
    "5. How long is the list `thing[low:high]`?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 6, 3]\n",
      "[3, 6, 3, 6, 7]\n",
      "[1, 4, 3, 6, 3]\n",
      "[1, 4, 3, 6, 3, 6, 7]\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "thing = [1, 4, 3, 6, 3, 6, 7]\n",
    "\n",
    "low = 2\n",
    "high = 5\n",
    "\n",
    "print(thing[low:high])\n",
    "print(thing[low:])\n",
    "print(thing[:high])\n",
    "print(thing[:])\n",
    "print(len(thing[low:high]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 2: Making Strides\n",
    "\n",
    "What does the following program print?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bree\n",
      "yelekreB\n"
     ]
    }
   ],
   "source": [
    "city = 'Berkeley'\n",
    "print(city[::2])\n",
    "print(city[::-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. If we write a [slice](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#slice) as low:high:stride, what does stride do?\n",
    "2. What expression would select all of the even-numbered items from a collection?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n"
     ]
    }
   ],
   "source": [
    "numbers = list(range(1,51))\n",
    "print(numbers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]\n"
     ]
    }
   ],
   "source": [
    "print(numbers[1::2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 3: Append vs. Extend\n",
    "\n",
    "Using the program below, can you tell the difference between the `append` method and the `extend` method?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "append does this: ['bread', 'pasta', 'beans', 'cereal', ['granola bars', 'cookies']]\n",
      "extend does this: ['bread', 'pasta', 'beans', 'cereal', 'granola bars', 'cookies']\n"
     ]
    }
   ],
   "source": [
    "pantry_1 = ['bread', 'pasta', 'beans', 'cereal']\n",
    "pantry_2 = ['bread', 'pasta', 'beans', 'cereal']\n",
    "new_items = ['granola bars', 'cookies']\n",
    "pantry_1.append(new_items)\n",
    "pantry_2.extend(new_items)\n",
    "print('append does this:', pantry_1)\n",
    "print('extend does this:', pantry_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 4: Index\n",
    "\n",
    "I've created a (long) list for you below. Use the `.index()` method to find out what the index number is for `Waldo`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Wheres_Waldo = [\"Anna\", \"Shad\", \"Rachel\", \"Maura\", \"Jason\", \"Matt\", \"Konrad\", \"Justine\", \"Sarah\", \"Laura\", \\\n",
    "                \"Chelsea\", \"Nina\", \"Dierdre\", \"Julian\", \"Waldo\", \"Naniette\", \"Melissa\", \"Biz\", \"Elsa\", \"Demetria\",\\\n",
    "                \"Liz\", \"Olivia\", \"Will\", \"Ogi\", \"Melanie\", \"Jessica\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Wheres_Waldo.index(\"Waldo\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 5:  join\n",
    "\n",
    "Read the help file for the `join` method. \n",
    "\n",
    "Using the join method, concatenate all the values in this list into one string:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "letters = ['s', 'p', 'a', 'm']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spam\n"
     ]
    }
   ],
   "source": [
    "print(''.join(letters))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now use the `join` method to make one string with all the names from the list `Wheres_Waldo`, which prints each name on a separate line. (HINT: Remember a new line is represented by `\\n`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Anna\n",
      "Shad\n",
      "Rachel\n",
      "Maura\n",
      "Jason\n",
      "Matt\n",
      "Konrad\n",
      "Justine\n",
      "Sarah\n",
      "Laura\n",
      "Chelsea\n",
      "Nina\n",
      "Dierdre\n",
      "Julian\n",
      "Waldo\n",
      "Naniette\n",
      "Melissa\n",
      "Biz\n",
      "Elsa\n",
      "Demetria\n",
      "Liz\n",
      "Olivia\n",
      "Will\n",
      "Ogi\n",
      "Melanie\n",
      "Jessica\n"
     ]
    }
   ],
   "source": [
    "print('\\n'.join(Wheres_Waldo))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Reverse the order of the names:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jessica\n",
      "Melanie\n",
      "Ogi\n",
      "Will\n",
      "Olivia\n",
      "Liz\n",
      "Demetria\n",
      "Elsa\n",
      "Biz\n",
      "Melissa\n",
      "Naniette\n",
      "Waldo\n",
      "Julian\n",
      "Dierdre\n",
      "Nina\n",
      "Chelsea\n",
      "Laura\n",
      "Sarah\n",
      "Justine\n",
      "Konrad\n",
      "Matt\n",
      "Jason\n",
      "Maura\n",
      "Rachel\n",
      "Shad\n",
      "Anna\n"
     ]
    }
   ],
   "source": [
    "print('\\n'.join(Wheres_Waldo[::-1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
